In pypot you can use a specific function - autodetect_robot - to automatically scan each usb2serial ports and creates a robot will all attached dynamixel motors. This is a convenient way to quickly plug a few motors and used them as a Robot.
You can create a robot for any configurations of robot (e.g. using multiple dynamixel buses) using:
In [1]:
from pypot.dynamixel import autodetect_robot
robot = autodetect_robot()
This will create a robot with all motors found attached:
In [2]:
[m.name for m in robot.motors]
Out[2]:
As you can see, motor's names are defined as motor_{id}
.
Note that obviously, pypot can't guess the motors offset and limits so default value will be used:
You can then use you robot as any other kind of robot:
In [3]:
robot.start_sync()
for m in robot.motors:
m.compliant = False
m.goal_position = 0.0
As scanning all ports can be time consumming, it's recommended to use autodetect_robot only once, and then to export the robot's configuration.
In [4]:
config = robot.to_config()
config
Out[4]:
The config can directly be edited: e.g. to change motor's names or set the correct offsets:
In [5]:
config['motors']['motor_13']['offset'] = 22.5
You can save it to a json file which can then easily be reloaded.
In [6]:
import json
with open('my-config.json', 'w') as f:
json.dump(robot.to_config(), f, indent=2)
In [7]:
robot.close()
In [8]:
from pypot.robot import from_json
robot = from_json('my-config.json')